package com.klangner.go.model.utils;

import junit.framework.TestCase;

import com.klangner.go.model.IBoard;
import com.klangner.go.model.impl.GoBoard;

public class BoardUtilsTest extends TestCase {

	/**
	 * ..x..
	 * .xox.
	 * ..x..
	 */
	public void testHasLiberty1() {
		IBoard		 		board = new GoBoard(9);
		
		board.setStone(1, 2, IBoard.BLACK_STONE);
		board.setStone(3, 2, IBoard.BLACK_STONE);
		board.setStone(2, 1, IBoard.BLACK_STONE);
		board.setStone(2, 3, IBoard.BLACK_STONE);
		assertFalse(BoardUtils.hasLiberty(board, 2, 2));
	}

	/**
	 * ..x..
	 * .xo..
	 * ..x..
	 */
	public void testHasLiberty2() {
		IBoard		 		board = new GoBoard(9);
		
		board.setStone(1, 2, IBoard.BLACK_STONE);
		board.setStone(2, 1, IBoard.BLACK_STONE);
		board.setStone(2, 3, IBoard.BLACK_STONE);
		assertTrue(BoardUtils.hasLiberty(board, 2, 2));
	}

	/**
	 * ..x..
	 * ..ox.
	 * ..x..
	 */
	public void testHasLiberty3() {
		IBoard		 		board = new GoBoard(9);
		
		board.setStone(3, 2, IBoard.BLACK_STONE);
		board.setStone(2, 1, IBoard.BLACK_STONE);
		board.setStone(2, 3, IBoard.BLACK_STONE);
		assertTrue(BoardUtils.hasLiberty(board, 2, 2));
	}

	/**
	 * .....
	 * .xox.
	 * ..x..
	 */
	public void testHasLiberty4() {
		IBoard		 		board = new GoBoard(9);
		
		board.setStone(1, 2, IBoard.BLACK_STONE);
		board.setStone(3, 2, IBoard.BLACK_STONE);
		board.setStone(2, 3, IBoard.BLACK_STONE);
		assertTrue(BoardUtils.hasLiberty(board, 2, 2));
	}

	/**
	 * ..x..
	 * ..ox.
	 * .....
	 */
	public void testHasLiberty5() {
		IBoard		 		board = new GoBoard(9);
		
		board.setStone(1, 2, IBoard.BLACK_STONE);
		board.setStone(2, 1, IBoard.BLACK_STONE);
		board.setStone(2, 3, IBoard.BLACK_STONE);
		assertTrue(BoardUtils.hasLiberty(board, 2, 2));
	}
	
	/**
	 * opposite color
	 */
	public void testOpposite(){
		
		assertEquals(IBoard.BLACK_STONE, BoardUtils.getOppositeColor(IBoard.WHITE_STONE));
	}
}
